/**    
 * @{#} BaseAdapter.java Create on 2014-5-30 下午7:54:44    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.evan.common.adapter;

import org.json.JSONArray;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class BaseAdapter extends android.widget.BaseAdapter {

	public LayoutInflater inflater;
	public Activity activity;
	public JSONArray array;
	public View[] views;

	public BaseAdapter(Activity activity, JSONArray array) {
		inflater = LayoutInflater.from(activity);
		this.activity = activity;
		this.array = array;
		views = new View[array.length()];
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		if (array == null) {
			return 0;
		}
		return array.length();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		try {
			return array.get(position);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return null;
	}

	public void notifyUpdate() {
		views = null;
		views = new View[array.length()];
		notifyDataSetChanged();
	}

	public void notifyUpdate(JSONArray array) {
		this.array = array;
		views = null;
		views = new View[array.length()];
		notifyDataSetChanged();
	}
}
